<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="日志类型1：报警 2：日志 3：其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logType">
              <j-dict-select-tag type="list" v-model="model.logType" dictCode="sm_log_type" placeholder="请选择日志类型1：报警 2：日志 3：其他" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="设备类型：1：门口机 2：室内机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceType">
              <j-dict-select-tag type="list" v-model="model.deviceType" dictCode="smzh_device_type" placeholder="请选择设备类型：1：门口机 2：室内机" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceId">
              <a-input v-model="model.deviceId" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="Sip 号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sipNo">
              <a-input v-model="model.sipNo" placeholder="请输入Sip 号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="通道号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="channel">
              <a-input-number v-model="model.channel" placeholder="请输入通道号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="证件类型 1:身份证 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certifiedType">
              <j-dict-select-tag type="list" v-model="model.certifiedType" dictCode="smzh_certified_type" placeholder="请选择证件类型 1:身份证 " />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="证件号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certifiedNo">
              <a-input v-model="model.certifiedNo" placeholder="请输入证件号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="触发时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="triggerTime">
              <a-input v-model="model.triggerTime" placeholder="请输入触发时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="事件编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventCode">
              <j-dict-select-tag type="list" v-model="model.eventCode" dictCode="smzh_event_code" placeholder="请选择事件编码" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="事件名称(别名)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eventName">
              <a-input v-model="model.eventName" placeholder="请输入事件名称(别名)"  ></a-input>
            </a-form-model-item>
          </a-col>
        <!--  <a-col :span="12">
            <a-form-model-item label="认证类型编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certifiedTypeCode">
              <a-input v-model="model.certifiedTypeCode" placeholder="请输入认证类型编码"  ></a-input>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="卡号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cardId">
              <a-input v-model="model.cardId" placeholder="请输入卡号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="被访人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="visit">
              <a-input v-model="model.visit" placeholder="请输入被访人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="房屋编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="houseCode">
              <a-input v-model="model.houseCode" placeholder="请输入房屋编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="楼层编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="floorNo">
              <a-input-number v-model="model.floorNo" placeholder="请输入楼层编号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="比对相似度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="similarity">
              <a-input-number v-model="model.similarity" placeholder="请输入比对相似度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="二进制图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="picString">
              <a-input v-model="model.picString" placeholder="请输入二进制图片" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="通行结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="result">
              <j-dict-select-tag type="list" v-model="model.result" dictCode="smzh_result" placeholder="请选择通行结果" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note">
              <a-input v-model="model.note" placeholder="请输入备注说明"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SmDeviceLogsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/smzh/smDeviceLogs/add",
          edit: "/smzh/smDeviceLogs/edit",
          queryById: "/smzh/smDeviceLogs/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>